﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;

namespace ShotgunApp
{
    public partial class SingleGame : PhoneApplicationPage
    {
        public static class AmmoCount
        {
            public static int userAmmo = startVars.startAmmo;
            public static int geniusAmmo = startVars.startAmmo;
        }

        public static class Global
        {
            public static string GeniusMove;
            public static string UserMove;
        }

        public SingleGame()
        {
            InitializeComponent();
            GeniusAmmo.Text = "ammo: " + AmmoCount.geniusAmmo;
            UserAmmo.Text = "ammo: " + AmmoCount.userAmmo;   
        }

        private void submit_Click(object sender, RoutedEventArgs e) // CLICK
        {

                if (((String)submit.Content) == "Submit")
                {
                    Move();
                    GeniusSpeak.Text = "Genius has moved"; //I know Genius hasn't actually moved yet
                    submit.Content = "Go!";

                    uReload.IsEnabled = false;
                    uFire.IsEnabled = false;
                    uShield.IsEnabled = false;
                    uReload.IsChecked = false;
                    uShield.IsChecked = false;
                    uFire.IsChecked = false;

                }
                else if (((String)submit.Content) == "Go!")
                {
                    GeniusSpeak.Text = "";
                    submit.Content = "Continue";

                    OutcomeDesc.Text = "Genius has: " + Genius(); //Genius moves here, didn't know how to ref w/out calling
                    GameOutcome();
                }
                else if (((String)submit.Content) == "Continue")
                {
                    OutcomeDesc.Text = "";
                    TextOutcome.Text = "";
                    submit.Content = "Submit";

                    uReload.IsEnabled = true;
                    uShield.IsEnabled = true;

                    if (AmmoCount.userAmmo != 0)
                    {
                        uFire.IsEnabled = true;
                    }
                    else
                    {
                        uFire.IsEnabled = false;
                    }
                }
                else if (((String)submit.Content) == "Statistics")
                {
                    
                }
            
        }

        public string Move() // MOVE
        {
            if (uReload.IsChecked.HasValue && uReload.IsChecked.Value == true)
            {
                UserAmmo.Text = "ammo: " + ++AmmoCount.userAmmo;
                Global.UserMove = "reloaded";
            }
            else if (uShield.IsChecked.HasValue && uShield.IsChecked.Value == true)
            {
                Global.UserMove = "shielded";
            }
            else if (uFire.IsChecked.HasValue && uFire.IsChecked.Value == true)
            {
                UserAmmo.Text = "ammo: " + --AmmoCount.userAmmo;
                Global.UserMove = "fired";
            }
            else
            {
                submit.Content = "Enter a move!";
            }


            return Global.UserMove;
        }

        public string Genius() // GENIUS
        {
            Random RandomNumber = new Random();
            int x = RandomNumber.Next(0, 3);

            if (startVars.startLevel == 1) // LEVEL 1
            {
                if (x == 0)
                {
                    Global.GeniusMove = "reloaded";
                    GeniusAmmo.Text = "ammo: " + ++AmmoCount.geniusAmmo;
                }
                else if (x == 1)
                {
                    Global.GeniusMove = "shielded";
                }
                else if (x == 2 && AmmoCount.geniusAmmo > 0)
                {
                    Global.GeniusMove = "fired";
                    GeniusAmmo.Text = "ammo: " + --AmmoCount.geniusAmmo;
                }
                else if (x == 2 && AmmoCount.geniusAmmo == 0)
                {
                    Global.GeniusMove = "reloaded";
                    GeniusAmmo.Text = "ammo: " + ++AmmoCount.geniusAmmo;
                }
            }
            else if (startVars.startLevel == 2) // LEVEL 2
            {
                if (AmmoCount.userAmmo == 0 && AmmoCount.geniusAmmo > 0)
                {
                    Global.GeniusMove = "fired";
                    GeniusAmmo.Text = "ammo: " + --AmmoCount.geniusAmmo;
                }
                else
                {
                    if (x == 0)
                    {
                        Global.GeniusMove = "reloaded";
                        GeniusAmmo.Text = "ammo: " + ++AmmoCount.geniusAmmo;
                    }
                    else if (x == 1)
                    {
                        Global.GeniusMove = "shielded";
                    }
                    else if (x == 2 && AmmoCount.geniusAmmo > 0)
                    {
                        Global.GeniusMove = "fired";
                        GeniusAmmo.Text = "ammo: " + --AmmoCount.geniusAmmo;
                    }
                    else if (x == 2 && AmmoCount.geniusAmmo == 0)
                    {
                        Global.GeniusMove = "reloaded";
                        GeniusAmmo.Text = "ammo: " + ++AmmoCount.geniusAmmo;
                    }
                }
            }

            
            return Global.GeniusMove;
        }

        public void GameOutcome()
        {

            if (Global.UserMove == "fired")
            {
                if (Global.GeniusMove == "reloaded")
                {
                    TextOutcome.Text = "VICTORY!";
                    submit.Content = "Statistics";

                    uReload.IsEnabled = false;
                    uFire.IsEnabled = false;
                    uShield.IsEnabled = false;
                }
                else if (Global.GeniusMove == "shielded")
                {
                    TextOutcome.Text = "ANOTHER ROUND...";
                    submit.Content = "Continue";
                }
                else if (Global.GeniusMove == "fired")
                {
                    TextOutcome.Text = "SUICIDE!";
                    submit.Content = "Statistics";

                    uReload.IsEnabled = false;
                    uFire.IsEnabled = false;
                    uShield.IsEnabled = false;
                }
            }
            else if (Global.UserMove == "shielded")
            {
                if (Global.GeniusMove == "reloaded")
                {
                    TextOutcome.Text = "ANOTHER ROUND...";
                    submit.Content = "Continue";
                }
                else if (Global.GeniusMove == "shielded")
                {
                    TextOutcome.Text = "ANOTHER ROUND...";
                    submit.Content = "Continue";
                }
                else if (Global.GeniusMove == "fired")
                {
                    TextOutcome.Text = "ANOTHER ROUND...";
                    submit.Content = "Continue";
                }
            }
            else if (Global.UserMove == "reloaded")
            {
                if (Global.GeniusMove == "reloaded")
                {
                    TextOutcome.Text = "ANOTHER ROUND...";
                    submit.Content = "Continue";
                }
                else if (Global.GeniusMove == "shielded")
                {
                    TextOutcome.Text = "ANOTHER ROUND...";
                    submit.Content = "Continue";
                }
                else if (Global.GeniusMove == "fired")
                {
                    TextOutcome.Text = "YOU LOST!";
                    submit.Content = "Statistics";

                    uReload.IsEnabled = false;
                    uFire.IsEnabled = false;
                    uShield.IsEnabled = false;
                }
            }
            else
            {
                TextOutcome.Text = "ANOTHER ROUND...";
                
            }
        }
    }
}